@extends('layouts.header')
@section('title','编辑')
@section('content')
    <article class="page-container">
        <form class="form form-horizontal" id="form" autocomplete="off">
            <div class="row cl">
                <label class="form-label col-sm-2">登录名：</label>
                <div class="formControls col-sm-4">
                    <input type="text" class="input-text" value="{{ $data->username }}" placeholder="" id="username" disabled>
                </div>
                <label class="form-label col-sm-2">真实姓名：</label>
                <div class="formControls col-sm-4">
                    <input type="text" class="input-text" value="{{ $data->realname }}" placeholder="" id="realname" disabled>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-sm-2">工号：</label>
                <div class="formControls col-sm-4">
                    <input type="text" class="input-text" value="{{ $data->num }}" placeholder="" id="num" disabled>
                </div>
                <label class="form-label col-sm-2">电话：</label>
                <div class="formControls col-sm-4">
                    <input type="text" class="input-text" value="{{ $data->telephone }}" placeholder="" id="telephone" disabled>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-sm-2">所在部门：</label>
                <div class="formControls col-sm-4">
                    <input type="text" class="input-text" value="{{ $data->depa }}" placeholder="" id="depa" disabled>
                </div>
                <label class="form-label col-sm-2">职务：</label>
                <div class="formControls col-sm-4">
                    <input type="text" class="input-text" value="{{ $data->position }}" placeholder="" id="position" disabled>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-sm-2">性别：</label>
                <div class="formControls col-sm-4">
                    <input type="text" class="input-text" value="{{ $data->gender == 1 ? '男':'女' }}" placeholder="" id="gender" disabled>
                </div>
                <label class="form-label col-sm-2">邮箱：</label>
                <div class="formControls col-sm-4">
                    <input type="text" class="input-text" value="{{ $data->email }}" placeholder="" id="email" disabled>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-sm-2">账号注册日期：</label>
                <div class="formControls col-sm-4">
                    <input type="text" class="input-text" value="{{ $data->created_at }}" placeholder="" id="created_at" disabled>
                </div>
                <label class="form-label col-sm-2">入职日期：</label>
                <div class="formControls col-sm-4">
                    <input type="text" class="input-text" value="{{ $data->work_date }}" placeholder="" id="work_date" disabled>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-sm-2">学历：</label>
                <div class="formControls col-sm-4">
                    <input type="text" class="input-text" value="{{ $data->edu }}" placeholder="" id="edu" disabled>
                </div>
                <label class="form-label col-sm-2">毕业院校：</label>
                <div class="formControls col-sm-4">
                    <input type="text" class="input-text" value="{{ $data->school }}" placeholder="" id="school" disabled>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-sm-2">出生日期：</label>
                <div class="formControls col-sm-4">
                    <input type="text" class="input-text" value="{{ $data->birth }}" placeholder="" id="birth" disabled>
                </div>
                <label class="form-label col-sm-2">职称：</label>
                <div class="formControls col-sm-4">
                    <input type="text" class="input-text" value="{{ $data->zhicheng }}" placeholder="" id="zhicheng" disabled>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-sm-2">持证情况：</label>
                <div class="formControls col-sm-10">
                    <input type="text" class="input-text" value="{{ $data->chizheng }}" placeholder="" id="chizheng" disabled>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-sm-2">主角色：</label>
                <div class="formControls col-sm-4">
                    <span class="select-box">
                        <select class="select" name="role_id" size="1">
                            @foreach($data_role as $val)
                                <option @if ($data->role_id==$val->id)selected @endif value="{{$val -> id}}">{{ $val->role_name }}</option>
                            @endforeach
                        </select>
                    </span>
                </div>
                <label class="form-label col-sm-2">是否为主检人：</label>
                <div class="formControls col-sm-4">
                    <span class="select-box">
                        <select class="select" id="istester" name="istester" size="1">
                            {{-- ，0-否，1-是 --}}
                            <option @if ($data->istester == '0')selected @endif value="0">否</option>
                            <option @if ($data->istester == '1')selected @endif value="1">是</option>
                        </select>
                    </span>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-sm-2">其他角色：</label>
                <div class="formControls col-sm-4">
                    <select class="select2 input-text" name="role_oids[]" multiple="multiple">
                        @foreach($data_role as $val)
                            <option @if (in_array($val->id,$data->role_oids)) selected @endif  value="{{$val -> id}}">{{ $val->role_name }}</option>
                        @endforeach
                    </select>
                </div>
                <label class="form-label col-sm-2">主检人代号：</label>
                <div class="formControls col-sm-4">
                    <input type="text" class="input-text" value="{{ $data->tester_code }}" placeholder="" id="tester_code" name="tester_code">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-sm-2">状态：</label>
                <div class="formControls col-sm-4">
                    <span class="select-box">
                        <select class="select" name="status" size="1">
                            {{-- 账号状态，1-未启用，2-启用，3-禁用 --}}
                            @if ($data->status == '1')
                                <option @if ($data->status == '1')selected @endif value="1">未启用</option>
                            @endif
                                <option @if ($data->status == '2')selected @endif value="2">已启用</option>
                                <option @if ($data->status == '3')selected @endif value="3">已禁用</option>
                        </select>
                    </span>
                </div>
                <label class="form-label col-sm-2">搭档副检姓名：</label>
                <div class="formControls col-sm-4">
                    <input type="text" class="input-text" value="{{ $data->partner }}" placeholder="" id="partner" name="partner">
                </div>
            </div>

            <div class="row cl">
                <div class="formControls col-sm-10 col-sm-offset-2">
                    <label style="color:red">* 必须为主检人指定一个副检。</label><br>
                    <label style="color:red">* 例如一支验电器启动电压的主检人是A，工频耐压的主检人是B，则合格证上的试验人员就是 A和B；</label><br>
                    <label style="color:red">* 假如这支验电器启动电压和工频耐压项目的主检人都是A，则合格证上的试验人员就是 A和副检。</label>
                </div>
            </div>


            @csrf

            <div class="row cl pt-20">
                <div class="col-sm-10 col-sm-offset-2">
                    <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                    <input class="btn btn-danger radius ml-15" type="button" value="&nbsp;&nbsp;取消&nbsp;&nbsp;" onclick="layer_close();">
                </div>
            </div>
        </form>
    </article>

    <script type="text/javascript">
        $(function () {

            var index2;
            $('.select2').select2();

            $('.skin-minimal input').iCheck({
                checkboxClass: 'icheckbox-blue',
                radioClass: 'iradio-blue',
                increaseArea: '20%'
            });

            $("#form").validate({
                rules: {
                    role_id: {
                        required: true,
                    },
                    status: {
                        required: true,
                    },
                },
                // onkeyup:false,
                // focusCleanup:false,
                success: "valid",
                submitHandler: function (form) {
                    $(form).ajaxSubmit({
                        type: 'post',
                        url: "",//自己提交给自己可以不写url   
                        //beforeSend  beforeSubmit
                        beforeSubmit: function () {
                            if ($('#istester').val() == '1' && $('#partner').val().trim() == '') {
                                layer.msg('必须为主检人指定一个副检', {time: 2000});
                                //如果验证不通过，返回false，阻止表单提交
                                return false;
                            }
                        },
                        beforeSend: function () {
                            //0.4透明度 白色遮罩
                            index2 = layer.load(2, {shade: [0.3, '#fff']});
                        },
                        complete: function () {
                            layer.close(index2);
                        },
                        success: function (data) {
                            //判断添加结果 
                            if (data === '1') {
                                // parent.window.location.reload();//刷新
                                parent.table_reload(0);//0停留在当前页，1回到第一页
                                parent.layer.msg('操作成功!', {icon: 1, time: 2000});
                                layer_close();//关闭自己
                            } else {
                                layer.msg('操作失败!', {icon: 2, time: 2000});
                            }
                        },
                        error: function (data) {
                            ajax_error(data);
                        }
                    });
                }
            });
        });
    </script>
    <!--/请在上方写此页面业务相关的脚本-->
@endsection